//
//  OwerRequest.m
//  LeaseMC
//
//  Created by fly驰 on 16/8/20.
//  Copyright © 2016年 XFKJ. All rights reserved.
//

#import "XFPostRequest.h"

//#import "MainPackage.h"
#import "HTTPRequestDefine.h"
//#import "XFDanweiModel.h"
//#import "XFReadNoteModel.h"


@implementation XFPostRequest

+(void)postGetVersionInfoByPlatform:(NSString *)platform
                            success:(HttpRequestSuccess)success
                            failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTVERSION;
    [httpRequest.parameters safeSetObject:platform forKey:@"platform"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

#pragma mark - 登录
+(void)postRequestLoginUsername:(NSString *)username
                       Password:(NSString *)password
                        success:(HttpRequestSuccess)success
                        failure:(HttpRequestFailed)failure{
    
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = SBBOOKLOGIN;
    [httpRequest.parameters safeSetObject:username forKey:@"username"];
    [httpRequest.parameters safeSetObject:password forKey:@"password"];
    [httpRequest.parameters safeSetObject:@"app" forKey:@"platform"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
    
}
#pragma mark - 测试cookie
+(void)postRequestTestCookieuserCode:(NSString *)userCode
                             success:(HttpRequestSuccess)success
                             failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = TESTCOOKIE;
    [httpRequest.parameters safeSetObject:userCode forKey:@"userCode"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

+(void)postRequestTestPictureImages:(UIImage *)images
                            success:(HttpRequestSuccess)success
                            failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = TESTUPICTURE;
    [httpRequest.parameters safeSetObject:@"103" forKey:@"userId"];
    [httpRequest.parameters safeSetObject:@"lan777" forKey:@"usercode"];
    NSMutableArray *picArr = [[NSMutableArray alloc] init];
    if (images!=nil) {
        NSDictionary *imageDic = @{@"name":@"images", @"filename":@"images.png", @"img":images};
        [picArr addObject:imageDic];
    }
    
    httpRequest.imgArr = picArr;
    return [httpRequest upLoadPicturesWithManager:[HttpRequest requestOperationManager]  success:^(id responseObject) {
        if (success !=nil) {
            success(responseObject);
        }
    } failure:^(NSError *error) {
        if (failure !=nil) {
            failure(error);
        }
    }];
}

+(void)postShopFootTypeshopId:(NSString *)shopId
                      success:(HttpRequestSuccess)success
                      failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTSHOPFOOTTYPE;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

#pragma mark - 添加店铺食品大类
+(void)postShopFootTypeAddItemshopId:(NSString *)shopId
                                Name:(NSString *)name
                             success:(HttpRequestSuccess)success
                             failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTADDSHOPFOOTTYPE;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:name forKey:@"name"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

#pragma mark - 添加店铺食品大类
/*
 * @param shopId
 * @param foodItemId -- 食品大类ID，数组
 * @param name
 * @param price
 * @param nowPrice
 * @param images
 * @param intro
 * @param paramData  --食品规格参数
 * @param title
 */
+(void)postShopAddFootItemshopId:(NSString *)shopId
                      foodItemId:(NSString *)foodItemId
                            Name:(NSString *)name
                           price:(NSString *)price
                        nowPrice:(NSString *)nowPrice
                          images:(UIImage *)images
                           intro:(NSString *)intro
                       paramData:(NSDictionary *)paramData
                           title:(NSString *)title
                         success:(HttpRequestSuccess)success
                         failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTADDSHOPFOOT;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:foodItemId forKey:@"foodItemId"];
    [httpRequest.parameters safeSetObject:name forKey:@"name"];
    [httpRequest.parameters safeSetObject:price forKey:@"price"];
    [httpRequest.parameters safeSetObject:nowPrice forKey:@"nowPrice"];
    [httpRequest.parameters safeSetObject:intro forKey:@"intro"];
    [httpRequest.parameters safeSetObject:paramData forKey:@"paramData"];
    [httpRequest.parameters safeSetObject:title forKey:@"title"];
    NSMutableArray *picArr = [[NSMutableArray alloc] init];
    if (images!=nil) {
        NSDictionary *imageDic = @{@"name":@"images", @"filename":@"images.png", @"img":images};
        [picArr addObject:imageDic];
    }
    
    httpRequest.imgArr = picArr;
    return [httpRequest upLoadPicturesWithManager:[HttpRequest requestOperationManager]  success:^(id responseObject) {
        if (success !=nil) {
            success(responseObject);
        }
    } failure:^(NSError *error) {
        if (failure !=nil) {
            failure(error);
        }
    }];
}

+(void)postShopChangeByfoodItems:(NSString *)foodItems
                          shopId:(NSString *)shopId
                      foodItemId:(NSString *)foodItemId
                            Name:(NSString *)name
                           price:(NSString *)price
                        nowPrice:(NSString *)nowPrice
                          images:(UIImage *)images
                           intro:(NSString *)intro
                       paramData:(NSDictionary *)paramData
                           title:(NSString *)title
                         success:(HttpRequestSuccess)success
                         failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTUPDATEFOODS;
    [httpRequest.parameters safeSetObject:foodItems forKey:@"id"];
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:foodItemId forKey:@"foodItemId"];
    [httpRequest.parameters safeSetObject:name forKey:@"name"];
    [httpRequest.parameters safeSetObject:price forKey:@"price"];
    [httpRequest.parameters safeSetObject:nowPrice forKey:@"nowPrice"];
    [httpRequest.parameters safeSetObject:intro forKey:@"intro"];
    [httpRequest.parameters safeSetObject:paramData forKey:@"paramData"];
    [httpRequest.parameters safeSetObject:title forKey:@"title"];
    NSMutableArray *picArr = [[NSMutableArray alloc] init];
    if (images!=nil) {
        NSDictionary *imageDic = @{@"name":@"images", @"filename":@"images.png", @"img":images};
        [picArr addObject:imageDic];
    }
    
    httpRequest.imgArr = picArr;
    return [httpRequest upLoadPicturesWithManager:[HttpRequest requestOperationManager]  success:^(id responseObject) {
        if (success !=nil) {
            success(responseObject);
        }
    } failure:^(NSError *error) {
        if (failure !=nil) {
            failure(error);
        }
    }];
}

#pragma mark - 大类排序修改
+(void)postShopFootTypeUpdateSortshopId:(NSString *)shopId
                            shopItemIds:(NSString *)shopItemIds
                                success:(HttpRequestSuccess)success
                                failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTSHOPFOOTTYPEUPDATE;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:shopItemIds forKey:@"shopItemIds"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark - 修改大类名字
+(void)postShopFootTypeUpdateShopFoodItemNameshopId:(NSString *)shopId
                                               Name:(NSString *)name
                                            type_id:(NSString *)type_id
                                            success:(HttpRequestSuccess)success
                                            failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = SHOPFOOTTYPEUPDATENAME;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:name forKey:@"name"];
    [httpRequest.parameters safeSetObject:type_id forKey:@"type_id"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark - 删除大类
+(void)postShopFootTypeDeleteShopFoodItemshopId:(NSString *)shopId
                                        type_id:(NSString *)type_id
                                        success:(HttpRequestSuccess)success
                                        failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTDELETESHOPFOOTTYPE;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:type_id forKey:@"id"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}


#pragma mark - 注册发送验证码
+(void)postUserGetVerifyCodeByUsername:(NSString *)userName
                               success:(HttpRequestSuccess)success
                               failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTGETREGISTERSMS;
    [httpRequest.parameters safeSetObject:userName forKey:@"userName"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark - 修改密码发送验证码
+(void)postChangePassWordGetVerifyCodeByUsername:(NSString *)userName
                                         success:(HttpRequestSuccess)success
                                         failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = THTCHANGEUSERPASSWORDVERIFY;
    [httpRequest.parameters safeSetObject:userName forKey:@"userName"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark - 注册服务员
+(void)postaddWaiterUsername:(NSString *)userName
                         sms:(NSString *)sms
                     success:(HttpRequestSuccess)success
                     failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTADDWAITER;
    [httpRequest.parameters safeSetObject:userName forKey:@"userName"];
     [httpRequest.parameters safeSetObject:sms forKey:@"sms"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark - 订单相关 status 1是正常用餐，2是预约的，3是历史，这里默认展示用户已支付的
+(void)postaddWaiterShopId:(NSString *)shopId
                    status:(NSInteger )status
                      page:(NSString *)page
                   success:(HttpRequestSuccess)success
                   failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTGETSHOPORDERV1;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
     [httpRequest.parameters safeSetObject:[NSString stringWithFormat:@"%zd",status] forKey:@"status"];
     [httpRequest.parameters safeSetObject:page forKey:@"page"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

#pragma mark -  根据大类查找食品
+(void)postfindFoodsByItemShopId:(NSString *)shopId
                       foodItems:(NSString *)foodItems
                         success:(HttpRequestSuccess)success
                         failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTFINDFOODSBYITEM;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:foodItems forKey:@"foodItems"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark -  根据 foodsId,查找大类
+(void)postfindTypeByfoodsId:(NSString *)foodsId
                       success:(HttpRequestSuccess)success
                       failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTFINDFOODSITEM;
    [httpRequest.parameters safeSetObject:foodsId forKey:@"foodsId"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark -  菜品恢复，又有菜品了
+(void)postHaveSallShopId:(NSString *)shopId
                  foodsId:(NSString *)foodsId
                  success:(HttpRequestSuccess)success
                  failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTUPDATEFOODSTOHAVE;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:foodsId forKey:@"foodsId"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

#pragma mark -  菜品卖完了
+(void)postSallAllShopId:(NSString *)shopId
                 foodsId:(NSString *)foodsId
                 success:(HttpRequestSuccess)success
                 failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTUPDATEFOODSTONOT;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:foodsId forKey:@"foodsId"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark -  增加二维码
+(void)postAddQRCodeShopId:(NSString *)shopId
                    tables:(NSString *)tables
                    action:(BOOL)action
                   success:(HttpRequestSuccess)success
                   failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTADDQRCODE;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:tables forKey:@"tables"];
    [httpRequest.parameters safeSetObject:[NSString stringWithFormat:@"%d",action] forKey:@"action"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

#pragma mark -  查看店铺二维码
+(void)postLookQRCodeByShopId:(NSString *)shopId
                      success:(HttpRequestSuccess)success
                      failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString = HTFINDQRCODEBYSHOPID;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark -  修改用户密码
+(void)postChangePassWordByUserName:(NSString *)userName
                                sms:(NSString *)sms
                           password:(NSString *)password
                            success:(HttpRequestSuccess)success
                            failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString = THTCHANGEUSERPASSWORD;
    [httpRequest.parameters safeSetObject:userName forKey:@"userName"];
    [httpRequest.parameters safeSetObject:sms forKey:@"sms"];
    [httpRequest.parameters safeSetObject:password forKey:@"password"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark - 修改店铺资料
+(void)postChangeShopDataByShopId:(NSString *)shopId
                 shopImage:(UIImage *)shopImage
                      name:(NSString *)name
                   address:(NSString *)address
               phoneNumber:(NSString *)phoneNumber
                     begin:(NSString *)begin
                       end:(NSString *)end
                     intro:(NSString *)intro
                   success:(HttpRequestSuccess)success
                   failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString    = HTUPDATESHOP;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:name forKey:@"name"];
    [httpRequest.parameters safeSetObject:address forKey:@"address"];
    [httpRequest.parameters safeSetObject:phoneNumber forKey:@"phoneNumber"];
    [httpRequest.parameters safeSetObject:begin forKey:@"begin"];
    [httpRequest.parameters safeSetObject:end forKey:@"end"];
    [httpRequest.parameters safeSetObject:intro forKey:@"intro"];
    NSMutableArray *picArr = [[NSMutableArray alloc] init];
    if (shopImage!=nil) {
        NSDictionary *imageDic = @{@"name":@"shopImage", @"filename":@"shopImage.png", @"img":shopImage};
        [picArr addObject:imageDic];
    }
    
    httpRequest.imgArr = picArr;
   return  [self upLoadPicturesWithManagerHttpRequest:httpRequest success:success failure:failure];
}
#pragma mark - 确定订单
+(void)postupdateSureOrderByShopId:(NSString *)shopId
                        outTradeNo:(NSString *)outTradeNo
                           success:(HttpRequestSuccess)success
                           failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString = HTSUREORDER;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    [httpRequest.parameters safeSetObject:outTradeNo forKey:@"outTradeNo"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

#pragma mark -  获取所有未读信息，返回总条数
+(void)postgetTotalUnReadByShopId:(NSString *)shopId
                          success:(HttpRequestSuccess)success
                          failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString = HTGETNOREADMESSAGE;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

#pragma mark -  正常订单未读
+(void)postGetNormalUnReadByShopId:(NSString *)shopId
                           success:(HttpRequestSuccess)success
                           failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString = HTGETNORMALORDERNOREAD;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}

#pragma mark -  预约订单未读
+(void)postGetReservationUnReadByShopId:(NSString *)shopId
                                success:(HttpRequestSuccess)success
                                failure:(HttpRequestFailed)failure{
    HttpRequest *httpRequest = [HttpRequest request];
    httpRequest.urlString = HTGETYUYUEORDERNOREAD;
    [httpRequest.parameters safeSetObject:shopId forKey:@"shopId"];
    return [self setWithHttpRequest:httpRequest success:success failure:failure];
}
/****************************************************/
+(void)setWithHttpRequest:(HttpRequest*)httpRequest success:(HttpRequestSuccess)success failure:(HttpRequestFailed)failure{
    
    [httpRequest postWithManager:[HttpRequest requestOperationManager] success:^(NSDictionary* responseObject) {
        if (success != nil) {
            success(responseObject);
        }
    } failure:^(NSError * error) {
        //        LGFLog(@"error = %@",error);
        if (failure !=nil) {
            failure(error);
        }
    }];
}
+(void)upLoadPicturesWithManagerHttpRequest:(HttpRequest*)httpRequest success:(HttpRequestSuccess)success failure:(HttpRequestFailed)failure{
    
    [httpRequest upLoadPicturesWithManager:[HttpRequest requestOperationManager] success:^(NSDictionary* responseObject) {
        if (success != nil) {
            success(responseObject);
        }
    } failure:^(NSError * error) {
        if (failure !=nil) {
            failure(error);
        }
    }];
}

@end
